package com.cskaoyan.exception;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
//@ResponseBody
//@RestControllerAdvice
public class ExceptionControllerAdvice {

    //写法和Handler方法一样
    @ExceptionHandler(ArithmeticException.class)
    public ModelAndView arithmeticException() {
        return new ModelAndView("/exception.jsp");
    }

    //可以在形参中，接收你抛出的异常
    @ExceptionHandler(SensitiveWordException.class)
    @ResponseBody
    public BaseRespVo sensitiveWord(SensitiveWordException exception) {
        return BaseRespVo.fail("松哥不行");
    }
}
